//
//  FRQSettingsViewController.m
//  FRQBluetoothKit_Example
//
//  Created by admin on 2023/10/23.
//  Copyright © 2023 xuchunhai. All rights reserved.
//

#import "FRQSettingsViewController.h"
#import "SettingsTableViewCell.h"
#import "FRQLoginViewController.h"
#import "FRQFeedbackViewController.h"
@interface FRQSettingsViewController ()
@property (nonatomic,strong) NSArray *arrImages;
@property (nonatomic,strong) NSArray *arrTitle;
@property (nonatomic,strong) NSArray *arrVcName;
@property (nonatomic,strong) UIButton *btnVerify;
@end

@implementation FRQSettingsViewController
- (UIButton *)btnVerify{
    if (nil==_btnVerify) {
        _btnVerify=[[UIButton alloc] initWithFrame:CGRectMake(125, 50, skScreenWidth-250, 42)];
        _btnVerify.backgroundColor=skUIColorFromRGB(0xdd7023);
        [_btnVerify setTitle:@"Log Out" forState:(UIControlStateNormal)];
        _btnVerify.titleLabel.font=[UIFont systemFontOfSize:13];
        [_btnVerify skSetBoardRadius:5 Width:0 andBorderColor:[UIColor clearColor]];
        @weakify(self)
        [[_btnVerify rac_signalForControlEvents:(UIControlEventTouchUpInside)] subscribeNext:^(__kindof UIControl * _Nullable x) {
            @strongify(self)
            [self clearAllUserDefaultsData2];
            UIViewController *view=[[FRQLoginViewController alloc] init];
            UINavigationController *nav=[[UINavigationController alloc] initWithRootViewController:view];
            [[[UIApplication sharedApplication] delegate] window].rootViewController=nav;
        }];
    }
    return _btnVerify;
}
/// 方法二：清除持久域
-(void)clearAllUserDefaultsData2{
    
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    
    NSDictionary *dic = [userDefaults dictionaryRepresentation];
    
    for(id key in dic){
        [userDefaults removeObjectForKey:key];
    }
    [userDefaults synchronize];
}
- (void)viewDidLoad {
    [super viewDidLoad];
//    self.title=@"Settings";
    self.navigationItem.title = @"Settings";
    // Do any additional setup after loading the view.
    [self.view addSubview:self.tableView];
    self.tableView.bounds=self.view.bounds;
    self.tableView.backgroundColor=skUIColorFromRGB(0x1c1f2a);
    
    if(KuserType==0){
        self.arrImages=@[@"device_ico_menu",@"wallet_ico_menu",@"security_ico_menu",@"notifications_ico_menu",@"support_ico_menu",@"about_ico_menu"];
        
        self.arrTitle=@[@"My Device",@"My Wallets",@"Account Security",@"Notifications",@"Support",@"About Tokenshow"];
        self.arrVcName=@[@"FRQMyDeviceViewController",@"FRQMyWalletsViewController",@"FRQAccountSecurityViewController",@"FRQNotificationsViewController",@"FRQSupportViewController",@"FRQAboutTokenshowViewController"];
    }else{
        self.arrImages=@[@"support_ico_menu",@"security_ico_menu",@"about_ico_menu"];
        
        self.arrTitle=@[@"Support",@"Account Security",@"About Tokenshow"];
        self.arrVcName=@[@"FRQDealerSupportViewController",@"FRQAccountSecurityViewController",@"FRQAboutTokenshowViewController"];
    }
    
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
#pragma mark - 代理方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.arrTitle.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 70;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 90;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 65;
}
- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *view=[[UIView alloc] init];
    view.frame=CGRectMake(0, 0, skScreenWidth, 120);
    [view addSubview:self.btnVerify];
    return view;
}
- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
    
    static NSString *cellIdentifier = @"SettingsTableViewCell";
    SettingsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = skXibView(@"SettingsTableViewCell");
    }
    NSString *imageName=self.arrImages[indexPath.row];
    NSString *titleName=self.arrTitle[indexPath.row];
    cell.imageIcon.image=[UIImage imageNamed:imageName];
    cell.labTitle.text=titleName;
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    NSString *vc=self.arrVcName[indexPath.row];
    if(KuserType==1){
        if(indexPath.row==0){
            UIViewController *view=[[NSClassFromString(vc) alloc] init];
            view.modalPresentationStyle=0;
            [self presentViewController:view animated:YES completion:^{
                
            }];
        }else{
            UIViewController *view=[[NSClassFromString(vc) alloc] init];
            [self.navigationController pushViewController:view animated:YES];
        }
        
    }else{
        UIViewController *view=[[NSClassFromString(vc) alloc] init];
        [self.navigationController pushViewController:view animated:YES];
    }
    
}
@end
